﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ElevatorAPI;

namespace WPFElevatorSimulator
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public delegate void PersonDelegate(Person personin);

        public delegate void StringDelegate(string stringin);

        public delegate void ElementDoubleDelegate(UIElement element, double doublein);

        //metrics
        private ushort _totalPeopleWaited;
        private ushort _totalPeopleRode;
        private uint _totalMoves;
        private DateTime _exerciseStart = DateTime.MinValue;
        private DateTime _exerciseEnd = DateTime.MinValue;

        private readonly ElevatorController.Controller_Sample _controllerA;
        private readonly ElevatorController.Controller_Sample _controllerB;
        private readonly ElevatorController.Controller_Sample _controllerC;

        private readonly Elevator _elevA = new Elevator {Visibility = Visibility.Collapsed};
        private readonly Elevator _elevB = new Elevator {Visibility = Visibility.Collapsed};
        private readonly Elevator _elevC = new Elevator {Visibility = Visibility.Collapsed};

        private static ElevatorController.ElevatorController _contextualController;
        private static Elevator _contextualElevator;
        private static StackPanel _contextualBuildingUI;

        public MainWindow()
        {
            InitializeComponent();

            #region BuildingA

            //first, add billboard, so it falls to its propper dynamic location...
            (BillboardA.Parent as Panel).Children.Remove(BillboardA);
            SimulatedBuildingAFloors.Children.Add(BillboardA);

            //create instance of students own controller.
            _controllerA = new ElevatorController.Controller_Sample(new List<ElevatorAPI.Floor>()
                                                                        //{
                                                                        //    new ElevatorAPI.Floor(10)
                                                                        //        {Name = "Executives"},
                                                                        //    new ElevatorAPI.Floor(9)
                                                                        //        {Name = "Accounting"},
                                                                        //    new ElevatorAPI.Floor(8)
                                                                        //        {Name = "Engineering"},
                                                                        //    new ElevatorAPI.Floor(7) {Name = "R&D"},
                                                                        //    new ElevatorAPI.Floor(6)
                                                                        //        {Name = "Customer Service"},
                                                                        //    new ElevatorAPI.Floor(5) {Name = "Testing"},
                                                                        //    new ElevatorAPI.Floor(4) {Name = "HR"},
                                                                        //    new ElevatorAPI.Floor(3) {Name = "Legal"},
                                                                        //    new ElevatorAPI.Floor(2)
                                                                        //        {Name = "Mail Room"},
                                                                        //    new ElevatorAPI.Floor(1) {Name = "Lobby"}
                                                                        //}
                                                                        );


            //draw floors to represent visual version of dll version            
            //foreach (ElevatorAPI.Floor f in _controllerA.Building.Floors.OrderByDescending(f => f.Number))
            //{
            //    var floor = new Floor();
            //    floor.SetFloorName(f.Name);
            //    floor.SetFloorNumber(f.Number.ToString());
            //    SimulatedBuildingAFloors.Children.Add(floor);
            //}

            tbStudentNameA.Text = _controllerA.StudentsName + " Towers";

            SetFloors(_controllerA);

            #endregion

            //#region BuildingB

            ////first, add billboard, so it falls to its propper dynamic location...
            //(BillboardB.Parent as Panel).Children.Remove(BillboardB);
            //SimulatedBuildingBFloors.Children.Add(BillboardB);

            ////create instance of students own controller.
            //_controllerB = new ElevatorController.Controller_CHodge(new List<ElevatorAPI.Floor>()
        


            ////draw floors to represent visual version of dll version            
            //foreach (ElevatorAPI.Floor f in _controllerB.Building.Floors.OrderByDescending(f => f.Number))
            //{
            //    var floor = new Floor();
            //    floor.SetFloorName(f.Name);
            //    floor.SetFloorNumber(f.Number.ToString());
            //    SimulatedBuildingBFloors.Children.Add(floor);
            //}

            //tbStudentNameB.Text = _controllerB.StudentsName + " Mall";

            //SetFloors(_controllerB);

            //#endregion

            //#region BuildingC

            ////first, add billboard, so it falls to its propper dynamic location...
            //(BillboardC.Parent as Panel).Children.Remove(BillboardC);
            //SimulatedBuildingCFloors.Children.Add(BillboardC);

            ////create instance of students own controller.
            //_controllerC = new ElevatorController.Controller_CHodge(new List<ElevatorAPI.Floor>()
        


            ////draw floors to represent visual version of dll version            
            //foreach (ElevatorAPI.Floor f in _controllerC.Building.Floors.OrderByDescending(f => f.Number))
            //{
            //    var floor = new Floor();
            //    floor.SetFloorName(f.Name);
            //    floor.SetFloorNumber(f.Number.ToString());
            //    SimulatedBuildingCFloors.Children.Add(floor);
            //}

            //tbStudentNameC.Text = _controllerC.StudentsName + " Suites";

            //SetFloors(_controllerC);

            //#endregion

            BuildingList.SelectedIndex = 0;
        }

        public void SetFloors(ElevatorController.ElevatorController c)
        {
            //subscribe to events
            //foreach (ElevatorAPI.Floor f in c.Building.Floors)
            //{
            //    f.OnCallButtonPressed += new ElevatorAPI.Floor.CallButtonPressedHandler(f_ElevatorCalled);
            //    f.OnPersonEnteredElevator += new ElevatorAPI.Floor.PersonEnteredElevatorHandler(f_PersonEnteredElevator);
            //    f.OnPersonExitedElevator += new ElevatorAPI.Floor.PersonExitedElevatorHandler(f_PersonExitedElevator);
            //    f.OnPersonWaitingForElevator += new ElevatorAPI.Floor.PersonWaitingForElevatorHandler(f_PersonWaitingForElevator);
            //}

            ////wireup all events to get all moves counter
            //c.Building.Elevator.OnElevatorDoorsOpened += new ElevatorAPI.Elevator.ElevatorDoorsOpenedHandler(Elevator_ElevatorDoorsOpened);
            //c.Building.Elevator.OnElevatorStopped += new ElevatorAPI.Elevator.ElevatorStoppedHandler(Elevator_ElevatorStopped);
            //c.Building.Elevator.OnElevatorStarted += new ElevatorAPI.Elevator.ElevatorStartedHandler(Elevator_ElevatorStarted);
            //c.Building.Elevator.OnElevatorFloorButtonPressed += new ElevatorAPI.Elevator.ElevatorFloorButtonPressedHandler(Elevator_ElevatorFloorButtonPressed);
            //c.Building.Elevator.OnElevatorDoorsClosed += new ElevatorAPI.Elevator.ElevatorDoorsClosedHandler(Elevator_ElevatorDoorsClosed);
            //c.Building.Elevator.OnElevatorMoved += new ElevatorAPI.Elevator.ElevatorMovedHandler(Elevator_ElevatorMoved);
        }

        private void f_PersonEnteredElevator(ElevatorAPI.Person personGettingOn, ElevatorAPI.Floor floorWaitingOn)
        {

            ////set people inside count manually
            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetPeopleInside),
            //                  _contextualController.Building.Elevator.PeopleInside.Count().ToString());

            ////manually move person from floor into elevator.
            //var thread = new System.Threading.Thread(
            //    () => Dispatcher.Invoke(
            //        System.Windows.Threading.DispatcherPriority.Normal,
            //        new Action(
            //            delegate
            //                {
            //                    var floorholder =
            //                        _contextualBuildingUI.Children.OfType<Floor>().First(
            //                            f => ushort.Parse(f.tbFloorNumber.Text) == floorWaitingOn.Number);

            //                    var p = floorholder.spWaitingPeople.Children[0];
            //                    floorholder.spWaitingPeople.Children.Remove(p);
            //                    _contextualElevator.AddPersonInside(p as Person);
            //                }
            //            )));

            //thread.Start();

            //_totalMoves++;
            //Console.WriteLine("Person Entered Elevator " + personGettingOn.Name + " --- " + floorWaitingOn.Name + " (" +
            //                  floorWaitingOn.Number + ")");

            //Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            //Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());
        }

        private void f_ElevatorCalled(object sender, Enumerations.ButtonPressed buttonPressed)
        {
            //Console.WriteLine("Elevator Called to floor " + (sender as ElevatorAPI.Floor).Name + "(" + (sender as ElevatorAPI.Floor).Number + ")" + " - Going " + buttonPressed.ToString());
            _totalMoves++;

            Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());
        }

        private void Elevator_ElevatorStopped(object sender, ElevatorAPI.Floor floorStoppedOn)
        {

            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetTrajectory), _contextualController.Building.Elevator.Trajectory.ToString());

            //Console.WriteLine("Elevator Stopped on " + floorStoppedOn.Name + " (" + floorStoppedOn.Number + ")");
            //_totalMoves++;

            //if (_contextualController.Building.Elevator.Trajectory == Enumerations.ElevatorTrajectory.Idle &&
            //    _contextualController.Building.Elevator.PeopleInside.Count == 0 &&
            //    _contextualController.Building.Floors.Where(f => f.PeopleWaiting.Count > 0).Count() == 0)
            //{
            //    _exerciseEnd = DateTime.Now;

            //    Console.WriteLine("--------------");
            //    Console.WriteLine("METRICS");
            //    Console.WriteLine("Total Time: " + (_exerciseEnd - _exerciseStart).TotalMilliseconds + "ms");
            //    Console.WriteLine("Total Waited: " + _totalPeopleWaited);
            //    Console.WriteLine("Total Rode: " + _totalPeopleRode);
            //    Console.WriteLine("Got all the passengers: " + (_totalPeopleRode == _totalPeopleWaited));
            //    Console.WriteLine("Total Actions Taken: " + _totalMoves);
            //    var result = (52101 - ((_exerciseEnd - _exerciseStart).TotalMilliseconds)) +
            //                 (100*((_totalPeopleRode == _totalPeopleWaited) ? 1 : 0)) + (25*(98 - _totalMoves));
            //    Console.WriteLine("Computed score: " + result);

            //    Dispatcher.Invoke(new StringDelegate(SetTotalTime), (_exerciseEnd - _exerciseStart).TotalMilliseconds + "ms");
            //    Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //    Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //    Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());
            //    Dispatcher.Invoke(new StringDelegate(SetScore), result.ToString());

            //    EnableTestButtons();
            //}


            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetPeopleInside), _contextualController.Building.Elevator.PeopleInside.Count().ToString());
            //Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            //Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());

        }

        private void Elevator_ElevatorMoved(object sender, ElevatorAPI.Floor floorStoppedOn, Enumerations.ElevatorTrajectory movementTrajectory)
        {

            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetTrajectory), _contextualController.Building.Elevator.Trajectory.ToString());
            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetPeopleInside), _contextualController.Building.Elevator.PeopleInside.Count().ToString());
            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetCurrentFloor), _contextualController.Building.Elevator.CurrentFloor.Number.ToString());
            //Dispatcher.Invoke(new ElementDoubleDelegate(Canvas.SetTop), _contextualElevator, 695.0 - (70*(floorStoppedOn.Number - 1)));

            //Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            //Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());

            //Console.WriteLine("Elevator Moved to " + floorStoppedOn.Name + " (" + floorStoppedOn.Number + ") by going " + movementTrajectory.ToString());
            //_totalMoves++;
        }

        private void Elevator_ElevatorFloorButtonPressed(object sender, ElevatorAPI.Floor floorRequested)
        {

            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetPeopleInside), _contextualController.Building.Elevator.PeopleInside.Count().ToString());

            //Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            //Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());

            //Console.WriteLine("Person Pressed Floor Selection Button " + floorRequested.Name + " (" + floorRequested.Number + ")");
            //_totalMoves++;

        }

        private void Elevator_ElevatorDoorsOpened(object sender, ElevatorAPI.Floor floorStoppedOn)
        {

            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetDoorState), _contextualController.Building.Elevator.DoorState.ToString());
            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetPeopleInside), _contextualController.Building.Elevator.PeopleInside.Count().ToString());

            //Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            //Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());

            //Console.WriteLine("Elevator Doors Opened on " + floorStoppedOn.Name + " (" + floorStoppedOn.Number + ")");
            //_totalMoves++;
        }

        private void Elevator_ElevatorDoorsClosed(object sender, ElevatorAPI.Floor floorStoppedOn)
        {
            //Console.WriteLine("Elevator Doors Closed on " + floorStoppedOn.Name + " (" + floorStoppedOn.Number + ")");
            //_totalMoves++;

            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetDoorState), _contextualController.Building.Elevator.DoorState.ToString());
            //Dispatcher.Invoke(new StringDelegate(_contextualElevator.SetPeopleInside), _contextualController.Building.Elevator.PeopleInside.Count().ToString());

            //Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            //Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());

        }

        private void f_PersonWaitingForElevator(ElevatorAPI.Person PersonGettingOn, ElevatorAPI.Floor floorWaitingOn)
        {
            //_totalMoves++;
            //_totalPeopleWaited++;

            ////find floor in question
            //var floorholder =
            //    _contextualBuildingUI.Children.OfType<Floor>().First(
            //        f => ushort.Parse(f.tbFloorNumber.Text) == floorWaitingOn.Number);

            ////make new person
            //var p = new Person();
            //p.SetName(PersonGettingOn.Name);
            //p.SetDestination(PersonGettingOn.DestinationFloor.Number.ToString());

            ////add together
            //floorholder.spWaitingPeople.Children.Add(p);

            //Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            //Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());

            //Console.WriteLine("Person Waiting For Elevator " + PersonGettingOn.Name + " --- " + floorWaitingOn.Name + " (" + floorWaitingOn.Number + ")");
        }

        private void f_PersonExitedElevator(ElevatorAPI.Person personGettingOff, ElevatorAPI.Floor floorExitingOn)
        {
            //_totalMoves++;
            //_totalPeopleRode++;

            ////manually move person from elevator into floor.
            //var thread = new System.Threading.Thread(
            //    () => Dispatcher.Invoke(
            //        System.Windows.Threading.DispatcherPriority.Normal,
            //        new Action(
            //            delegate
            //                {
            //                    var floorholder =
            //                        _contextualBuildingUI.Children.OfType<Floor>().First(
            //                            f => ushort.Parse(f.tbFloorNumber.Text) == floorExitingOn.Number);

            //                    var p = _contextualElevator.spRiders.Children[0];
            //                    _contextualElevator.RemovePersonInside(p as Person);
            //                    floorholder.spExitedPeople.Children.Add(p);
            //                }
            //            )));

            //thread.Start();

            //Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            //Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            //Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());

            //Console.WriteLine("Person Exited Elevator " + personGettingOff.Name + " --- " + floorExitingOn.Name + " (" + floorExitingOn.Number + ")");
            //Console.WriteLine("Person Completed their trip and exited the elevator." + personGettingOff.Name + " got off on floor " + floorExitingOn.Name + "(" + floorExitingOn.Number + ")." + " Person waited for elevator for " + personGettingOff.TotalWaitingTime.Value.TotalMilliseconds + "ms and rode for " + personGettingOff.TotalRidingTime.Value.TotalMilliseconds + "ms");
        }

        private void Elevator_ElevatorStarted(object sender)
        {
            Console.WriteLine("Elevator Started ");
            _totalMoves++;

            Dispatcher.Invoke(new StringDelegate(SetTotalTime), (DateTime.Now - _exerciseStart).TotalMilliseconds + "ms");
            Dispatcher.Invoke(new StringDelegate(SetPeopleWaiting), _totalPeopleWaited.ToString());
            Dispatcher.Invoke(new StringDelegate(SetPeopleDelivered), _totalPeopleRode.ToString());
            Dispatcher.Invoke(new StringDelegate(SetNumberOfMoves), _totalMoves.ToString());
        }

        #region metrics

        private void SetTotalTime(string time)
        {
            tbTotalTime.Text = time;
        }

        private void SetPeopleWaiting(string people)
        {
            tbPeopleWaiting.Text = people;
        }

        private void SetPeopleDelivered(string people)
        {
            tbPeopleDelivered.Text = people;
        }

        private void SetNumberOfMoves(string moves)
        {
            tbNumberOfMoves.Text = moves;
        }

        private void SetScore(string score)
        {
            tbScore.Text = score;
        }

        #endregion

        #region test buttons

        #region test 1

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            _contextualController = _controllerA;
            _contextualElevator = _elevA;
            _contextualBuildingUI = SimulatedBuildingAFloors;

            _elevA.Visibility = Visibility.Visible;
            _elevC.Visibility = Visibility.Collapsed;
            _elevB.Visibility = Visibility.Collapsed;

            DisableTestButtons();

            //ONLY DO THIS WHEN THE TEST IS STARTED, THAT WAY WE ONLY SEE ONE AT A TIME.
            //set elevator to initial floor
            //Console.WriteLine("Elevator Started at " + _controllerA.Building.Elevator.CurrentFloor.Name + "(" + _controllerA.Building.Elevator.CurrentFloor.Number + ") with its doors " + _controllerA.Building.Elevator.DoorState);
            //_contextualElevator.SetDoorState(_controllerA.Building.Elevator.DoorState.ToString());
            //_contextualElevator.SetTrajectory(_controllerA.Building.Elevator.Trajectory.ToString());
            //_contextualElevator.SetPeopleInside(_controllerA.Building.Elevator.PeopleInside.Count().ToString());
            //_contextualElevator.SetCurrentFloor(_controllerA.Building.Elevator.DefaultElevatorFloor.Number.ToString());
            Canvas.SetLeft(_contextualElevator, 145.0);
            Canvas.SetTop(_contextualElevator, 695.0);
            Panel.SetZIndex(_contextualElevator, 999);
            LayoutRoot.Children.Add(_contextualElevator);

            //input test characteristics   
            _exerciseStart = DateTime.Now;

            //_contextualController.Building.Floors.First(f => f.Number == 10).AddPersonToFloorWaitingForElevator(new ElevatorAPI.Person()
            //                                           {
            //                                               Name = "Levi",
            //                                               DestinationFloor = _contextualController.Building.Floors.First(f => f.Number == 1)
            //                                           });
            //_contextualController.Building.Floors.First(f => f.Number == 6).AddPersonToFloorWaitingForElevator(new ElevatorAPI.Person()
            //                                           {
            //                                               Name = "Jairo",
            //                                               DestinationFloor = _contextualController.Building.Floors.First(f => f.Number == 2)
            //                                           });
            //_contextualController.Building.Floors.First(f => f.Number == 4).AddPersonToFloorWaitingForElevator(new ElevatorAPI.Person()
            //                                           {
            //                                               Name = "John",
            //                                               DestinationFloor = _contextualController.Building.Floors.First(f => f.Number == 4)
            //                                           });
            //_contextualController.Building.Floors.First(f => f.Number == 2).AddPersonToFloorWaitingForElevator(new ElevatorAPI.Person()
            //                                           {
            //                                               Name = "James",
            //                                               DestinationFloor = _contextualController.Building.Floors.First(f => f.Number == 9)
            //                                           });
            //_contextualController.Building.Floors.First(f => f.Number == 9).AddPersonToFloorWaitingForElevator(new ElevatorAPI.Person()
            //                                           {
            //                                               Name = "Donald",
            //                                               DestinationFloor = _contextualController.Building.Floors.First(f => f.Number == 1)
            //                                           });
            //_contextualController.Building.Floors.First(f => f.Number == 9).AddPersonToFloorWaitingForElevator(new ElevatorAPI.Person()
            //                                           {
            //                                               Name = "William",
            //                                               DestinationFloor = _contextualController.Building.Floors.First(f => f.Number == 10)
            //                                           });

            //_contextualController.Building.Elevator.Start();

    }

        private void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            BuildingList.SelectedIndex = 0;
            BuildingList.ScrollIntoView(BuildingList.Items[0]);
        }
      
        #endregion

        #region test 2
        private void Button_MouseEnter_1(object sender, MouseEventArgs e)
        {
            BuildingList.SelectedIndex = 1;
            BuildingList.ScrollIntoView(BuildingList.Items[1]);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            _contextualController = _controllerB;
            _contextualElevator = _elevB;
            _contextualBuildingUI = SimulatedBuildingBFloors;

            _elevA.Visibility = Visibility.Collapsed;
            _elevB.Visibility = Visibility.Visible;
            _elevC.Visibility = Visibility.Collapsed;

            DisableTestButtons();

            //set elevator to initial floor
            //Console.WriteLine("Elevator Started at " + _contextualController.Building.Elevator.CurrentFloor.Name + "(" + _contextualController.Building.Elevator.CurrentFloor.Number + ") with its doors " + _contextualController.Building.Elevator.DoorState);
            //_contextualElevator.SetDoorState(_contextualController.Building.Elevator.DoorState.ToString());
            //_contextualElevator.SetTrajectory(_contextualController.Building.Elevator.Trajectory.ToString());
            //_contextualElevator.SetPeopleInside(_contextualController.Building.Elevator.PeopleInside.Count().ToString());
            //_contextualElevator.SetCurrentFloor(_contextualController.Building.Elevator.DefaultElevatorFloor.Number.ToString());
            Canvas.SetLeft(_contextualElevator, 145.0);
            Canvas.SetTop(_contextualElevator, 695.0);
            Panel.SetZIndex(_contextualElevator, 999);
            LayoutRoot.Children.Add(_contextualElevator);

            //input test characteristics   
            _exerciseStart = DateTime.Now;

           //put in test scenario here.
           
            //_contextualController.Building.Elevator.Start();

        }
        #endregion

        #region test 3
        private void Button_MouseEnter_2(object sender, MouseEventArgs e)
        {
            BuildingList.SelectedIndex = 2;
            BuildingList.ScrollIntoView(BuildingList.Items[2]);
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            _contextualController = _controllerC;
            _contextualElevator = _elevC;
            _contextualBuildingUI = SimulatedBuildingCFloors;

            _elevA.Visibility = Visibility.Collapsed;
            _elevB.Visibility = Visibility.Collapsed;
            _elevC.Visibility = Visibility.Visible;

            DisableTestButtons();

            //set elevator to initial floor
            //Console.WriteLine("Elevator Started at " + _contextualController.Building.Elevator.CurrentFloor.Name + "(" + _contextualController.Building.Elevator.CurrentFloor.Number + ") with its doors " + _contextualController.Building.Elevator.DoorState);
            //_contextualElevator.SetDoorState(_contextualController.Building.Elevator.DoorState.ToString());
            //_contextualElevator.SetTrajectory(_contextualController.Building.Elevator.Trajectory.ToString());
            //_contextualElevator.SetPeopleInside(_contextualController.Building.Elevator.PeopleInside.Count().ToString());
            //_contextualElevator.SetCurrentFloor(_contextualController.Building.Elevator.DefaultElevatorFloor.Number.ToString());
            Canvas.SetLeft(_contextualElevator, 145.0);
            Canvas.SetTop(_contextualElevator, 695.0);
            Panel.SetZIndex(_contextualElevator, 999);
            LayoutRoot.Children.Add(_contextualElevator);

            //input test characteristics   
            _exerciseStart = DateTime.Now;

           //put in test scenario here

        }
        
        #endregion
       
        #endregion

        private void DisableTestButtons()
        {
            Dispatcher.Invoke(new Action(delegate { test1btn.IsEnabled = false; }));
            Dispatcher.Invoke(new Action(delegate { test2btn.IsEnabled = false; }));
            Dispatcher.Invoke(new Action(delegate { test3btn.IsEnabled = false; }));
        }

        private void EnableTestButtons()
        {
            Dispatcher.Invoke(new Action(delegate { test1btn.IsEnabled = true; }));
            Dispatcher.Invoke(new Action(delegate { test2btn.IsEnabled = true; }));
            Dispatcher.Invoke(new Action(delegate { test3btn.IsEnabled = true; }));
        }
       
    }
}